package main;

import java.io.FileWriter;
import java.io.Writer;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CSVFileCreator {
	public CSVFileCreator(int[][][] data, int[][] mapConstants)
	{}
	public static void createCSVFile(double[][][] data, int[][] mapConstants)
	{
		try
		{
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss");
			String filename = "TestRun_" + df.format(new Date()) + ".csv"; 
			BufferedWriter output = null;
			File file = new File(filename);
			output = new BufferedWriter(new FileWriter(file));
			output.write("Each intelligence type was run "+mapConstants[4][0]+" times for each map type");
			output.newLine();
			output.write("The value of all measured units is steps and this value represents the movement from one grid space to another");
			output.newLine();
			output.newLine();
			for (int mapNumber = 0; mapNumber < data[0][0].length; mapNumber++)
			{
				output.write(" , , , , , "+mapConstants[3][mapNumber]+"% Density Map with Category "+mapConstants[0][mapNumber]+" Range");
				output.newLine();
				output.newLine();
				output.write(" ,,,, Minimum,, 1st Quartile,, 2nd Quartile,, 3rd Quartile,, Maximum,, Average, Standard Deviation");
				output.newLine();
				for (int intelligenceNumber = 0; intelligenceNumber < data.length; intelligenceNumber++)
				{
					String intelligenceName = "No Value Given";
					switch(intelligenceNumber)
					{
					case 0: intelligenceName = "Swarm Intelligence with 2 Agents";
					break;
					case 1: intelligenceName = "Swarm Intelligence with 4 Agents";
					break;
					case 2: intelligenceName = "Swarm Intelligence with 8 Agents";
					break;
					case 3: intelligenceName = "Artificial Intelligence with Vision of 2";
					break;
					case 4: intelligenceName = "Artificial Intelligence with Vision of 3";
					break;
					case 5: intelligenceName = "Artificial Intelligence with Vision of 4";
					break;
					}
					output.write(intelligenceName + ",,,,");
					for (int values = 0; values < data[0].length; values++)
					{
						output.write(""+data[intelligenceNumber][values][mapNumber]+",");
						if (values != 5)
							output.write(',');
					}
					output.newLine();	
				}
				output.newLine();
				output.write("The exact range of the two endpoints of this map was "+mapConstants[1][mapNumber]+",,,,,,");
				output.write("The value of the control variable for this map was "+mapConstants[2][mapNumber]+"");
				output.newLine();
				output.newLine();
				output.newLine();
			}
		    output.close();
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
	}
}
